package com.gold.web;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gold.model.Bank;
import com.gold.model.User;
import com.gold.service.BankService;
import com.gold.service.UserService;
import com.gold.util.BaseController;
import com.gold.util.Constant;
import com.gold.util.MsgUtils;
import com.gold.util.RandomValidateCode;

/**
 * Created by wxf
 * 员工登录
 */
@Controller
@RequestMapping(value="bank")
public class BankContorller extends BaseController{

    @Resource
    private BankService bankService;
    
    @RequestMapping(value="")
    public ModelAndView toBankVIew(HttpServletRequest request) {
		ModelAndView mo=new ModelAndView();
		mo.setViewName("bank");
		return mo;
	}
    
    @RequestMapping(value="/save")
    @ResponseBody
    public JSONObject save(HttpServletRequest request,Bank bank) {
		JSONObject jo=new JSONObject();
		boolean b=false;
		try {
			if(bank.getbId()==null)//说明是添加
				b=bankService.save(bank);
			else if(bank.getbId()>0)//说明是修改
				b=bankService.update(bank);
			jo.put("success", b);
			if(b){
				jo.put("msg","保存成功");
			}else{
				jo.put("msg","保存失败");
			}
		} catch (Exception e) {
			jo.put("msg", "发生了异常");
		}
		return jo;
	}
    
    @RequestMapping(value="/getAll")
    @ResponseBody
    public Map<String, List> getAll(){
    	Map<String, List> map=new HashMap<String,List>();
    	List<Bank> list=bankService.findAll();
    	map.put("Rows", list);
    	return map;
    }
}
